<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('推荐药维护')" />
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>

                        <li class="select-time">
                            <label>时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="查询时间" name="endTime"/>
                           <!-- <span>-</span>-->
                           <!-- <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>-->
                        </li>

                        <!-- <li>
                             拼音码：<input type="text" name="plucode" th:placeholder="条码"/>
                         </li>-->
<!--                        <li>
                            商品名称：<input type="text" name="goodsname" th:placeholder="商品名称"/>
                        </li>-->

<!--                        <li>
                            药品类型：<select name="classname"  id="deviceType">
                            <option value="">-&#45;&#45;请选择-&#45;&#45;</option>
                            <option value="中成药类">中成药类</option>
                            &lt;!&ndash;                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>&ndash;&gt;
                            &lt;!&ndash; <option th:each="deviceType : ${deviceTypeList}" th:text="${deviceType}" th:value="${deviceType}"></option>&ndash;&gt;
                            &lt;!&ndash;<option value="食品类">食品类</option>&ndash;&gt;
                            <option value="西药类">西药类</option>
                            &lt;!&ndash;<option value="参茸类">参茸类</option>&ndash;&gt;
                            &lt;!&ndash;<option value="医疗器械类">医疗器械类</option>&ndash;&gt;
                            &lt;!&ndash;<option value="饮片类">饮片类</option>&ndash;&gt;
                            <option value="进口药品类">进口药品类</option>
                            &lt;!&ndash;<option value="计生用品类">计生用品类</option>&ndash;&gt;
                            &lt;!&ndash;<option value="西药类">西药类</option>&ndash;&gt;
                            &lt;!&ndash;<option value="生物制品">生物制品</option>&ndash;&gt;

                        </select>
                        </li>-->

                        <li hidden>
                            <input id="flag3" name="flag3" value="1"></input>
                        </li>
                        <!--                        <li>
                                                    客户名称：<input type="text" name="companyName"/>
                                                </li>-->
                        <!--  <li>
                              岗位状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                              <option value="">所有</option>
                              <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                          </select>
                          </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>

                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--            <a class="btn btn-success" onclick="$.operate.add()" >
                            <i class="fa fa-plus"></i> 新增
                        </a>-->
<!--            <a class="btn btn-success" onclick="link()" >
                <i class="fa"></i> 新增药品关系
            </a>-->
            <!--            <a class="btn btn-success" onclick="recommend()" >
                            <i class="fa"></i> 新增为推荐
                        </a>-->
            <!--            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
                            <i class="fa fa-edit"></i> 修改
                        </a>-->
            <!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
                            <i class="fa fa-remove"></i> 删除
                        </a>-->
            <!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:post:export">
                            <i class="fa fa-download"></i> 导出
                        </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
    <!--    <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="post-form1">
                    <div class="select-list">
                        <ul>
                            <li>
                                药品信息：<input type="text" name="plucode" th:placeholder="店内码或拼音码"/>
                            </li>
                            &lt;!&ndash;                        <li>
                                                        客户名称：<input type="text" name="companyName"/>
                                                    </li>&ndash;&gt;
                            &lt;!&ndash;  <li>
                                  岗位状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                  <option value="">所有</option>
                                  <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                              </select>
                              </li>&ndash;&gt;
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>-->

    <!--        <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" >
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:post:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->

    <!--        <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table1"></table>
            </div>-->
</div>
</div>


<th:block th:include="include :: footer" />
<script th:inline="javascript">
    //  var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    // var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "baodao/check";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            /*  sortName: "companyId",*/
            modalName: "药品关系",
            // 测试父子表
            detailView: false,
            // 测试新增 查询条件
            /* queryParams: function(params) {
                 var curParams = {
                     // 传递参数查询参数
                     pageSize: params.limit,
                     pageNum: params.offset / params.limit + 1,
                     searchValue: params.search,
                     orderByColumn: params.sort,
                     isAsc: params.order,
                     // 新增 flag 为0 展示全部 药品信息，为1 展示药品关联表中已建立关系的药品列表
                     //   flag:  $("#flag").val()
                     flag: 0
                 }
                 return curParams;
             },*/
            columns: [
                {
                    field: 'no',
                    title: '序号',
                   // sortable: true,
                  //  align: "center",
                    width: 60,
                    formatter: function (value, row, index) {
                      /*  //获取每页显示的数量
                        var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页
                        var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
                        //返回序号，注意index是从0开始的，所以要加上1
                        return pageSize * (pageNumber - 1) + index + 1;*/
                        return index + 1;
                    }
                },

                {
                    field: 'sellNo',
                    title: '票号'
                },
                {
                    field: 'endTime',
                    title: '支付时间'
                },
                {
                    field: 'totalFee',
                    title: '支付金额'
                },
                {
                    field: 'payType',
                    title: '支付方式'
                },
                {
                    field: 'userId',
                    title: '用户id'
                },

                /*             {
                                 field: '',
                                 title: '原研药推荐'
                             },
                             {
                                 field: '',
                                 title: '关联药品推荐'
                             },*/
                //注册加载子表的事件。注意下这里的三个参数！

                /*                {
                                    title: '操作',
                                    align: 'center',
                                    formatter: function(value, row, index) {
                                        var actions = [];
                                       /!* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');*!/
                                     /!*   actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodscode + '\')"><i class="fa fa-edit"></i>编辑</a> ');*!/
                                        /!* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*!/
                                       /!* actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');*!/
                                        return actions.join('');
                                    }
                                }*/
            ],
            onExpandRow: function (index, row, $detail) {
                //oInit.InitSubTable(index, row, $detail);
                console.log("展开子表")
                console.log("行数据：" + "index:" + index )
                console.log(row)
                initSubTable(index,row,$detail)
            }

        };
        $.table.init(options);
    });
</script>

<script>
    // 获得所有选中的数据
    function link() {
        // $.table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        console.log("已选择数据数量：" + rows.length)
        console.log("已选择数据" + rows.toString())
        let id = rows.toString();
        let url = ctx + 'baodao/demo02/add' + '?id=' + id;
        console.log("弹窗 url" + url)
        var result = url.replace(/#/g, '%23');
        $.modal.openTab("新增药品关系",result);
        // 关闭本窗口
        // var index = ctx + '/baodao/demo02';
        $.modal.close(prefix);
    }
    /*    function recommend() {
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            console.log("已选择数据数量：" + rows.length)
            console.log("已选择数据" + rows.toString())
            let id = rows.toString();
            let url = ctx + 'baodao/demo01/edit' + '?id=' + id;
            console.log("弹窗 url" + url)
            var result = url.replace(/#/g, '%23');
            $.modal.openTab("新增为关联",result);
        }*/
    //初始化子表格(无线循环)
    initSubTable = function (index, row, $detail) {

        function queryParams(){
            let tmp = {"goodsCode":row.goodscode};
            return tmp;
        }
        var parentid = row.id;
        var cur_table = $detail.html('<table></table>').find('table');
        //  var cur_table = $detail.html('<table><title>测试</title></table>').find('table');
        $(cur_table).bootstrapTable({
            url: ctx + 'baodao/demo02/queryGoodsLink',
            method: 'post',
            contentType: 'application/x-www-form-urlencoded',
            queryParams:queryParams(),
            //data: {'goodsCode':'401-01-330'},
            ajaxOptions: { id: parentid },
            uniqueId: "id",
            striped: true, //是否显示行间隔色
            pagination: true,//显示分页
            sidePagination: "client",
            pageNumber:1,
            pageSize: 4,
            pageList: [4, 25],
            columns: [
                {
                    field: '',
                    title: '关联药品'
                },
                {
                    field: 'goodscode',
                    title: '内码'
                },
                {
                    field: 'goodsname',
                    title: '名称'
                },
                {
                    field: 'mfrs',
                    title: '厂商'
                },
                {
                    field: 'norm',
                    title: '规格'
                },
                /*                {
                                    field: 'plucode',
                                    title: '关联药品推荐'
                                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');*/
                        /*   actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodscode + '\')"><i class="fa fa-edit"></i>编辑</a> ');*/
                        /* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        /* actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        return actions.join('');
                    }
                }
                /*    {
                        field: 'mfrs',
                        title: '生产企业'
                    },
                    {
                        field: 'norm',
                        title: '包装规则'
                    },
                    {
                        field: 'plucode',
                        title: '条码'
                    },*/
            ],
            //无线循环取子表，直到子表里面没有记录
            onExpandRow: function (index, row, $Subdetail) {
                initSubTable(index, row, $Subdetail);
            }
        });
    };


</script>
</body>
</html>